/**
 * 
 */
package No301_400.No381_390.ShuffleanArray_384;

import java.util.Arrays;
import java.util.Random;

/** 
 * @author  作者 E-mail: ttljtw@qq.com
 * @date 创建时间：2017年3月3日 下午8:04:46 
 * @version 1.0 
 * @parameter  
 * @since  
 * @return  
 */
/**
 * @author 李敬
 *
 */
public class Solution {


    int[] a;
    public Solution(int[] nums) {
        a = new int[nums.length];
        for(int i = 0;i<nums.length;i++){
            a[i] = nums[i];
        }
    }
    
    /** Resets the array to its original configuration and return it. */
    public int[] reset() {
        return a;
    }
    
    /** Returns a random shuffling of the array. */
    public int[] shuffle() {
    	int n = a.length;
    	int[] b = new int[n];
    	Random r = new Random();///////////////
    	int i = 0;
    	while(i < n){
    		int j = r.nextInt(n);////////////// Random 的方法需要牢记
    		while (b[j] != 0) {
				j = r.nextInt(n);
			}
    		b[j] = a[i++];
    	}
        return b;
    }
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int[] nums = {1,2,3};
		Solution obj = new Solution(nums);
		System.out.println(Arrays.toString(obj.shuffle()));
		System.out.println(Arrays.toString(obj.reset()));
	}

}
